#!/bin/sh
# This shell script used to cross compile Busybox for fl2440
# Before excute this shell script, please download the source code to here first.
# Download Address: http://www.busybox.net/downloads/busybox-1.17.1.tar.bz2

APP_NAME=busybox-1.17.1
PACK_SUFFIX=tar.bz2
PATCH_FILE=./patch/fl2440-$APP_NAME.config
KEY="CROSS_COMPILE ?="
INSTEAD="CROSS_COMPILE ?= /opt/buildroot-eabi/staging/usr/bin/arm-linux-"

if [ ! -d ${APP_NAME} ] ; then
   if [ -f ${APP_NAME}.${PACK_SUFFIX} -a -f $PATCH_FILE ] ; then
        echo "==================================================="
        echo "+           Decompress $APP_NAME now...            "
        echo "==================================================="
        rm -rf ${APP_NAME}
        tar -xjf ${APP_NAME}.${PACK_SUFFIX}
        
        echo "===================================================" 
        echo "+         Patching and build now...                " 
        echo "===================================================" 
        cp -af ${PATCH_FILE} ${APP_NAME}/.config
        sed -i -e "s@${KEY}@$INSTEAD@g" ${APP_NAME}/Makefile
  else 
          echo "==========================================================================" 
          echo "+       ERROR: Missing $APP_NAME Source Code Packet!                      " 
          echo "+ Plese download ${APP_NAME}.${PACK_SUFFIX} to here and try again! " 
          echo "+ Download: http://www.busybox.net/downloads/busybox-1.17.1.tar.bz2 " 
          echo "===========================================================================" 
          exit; 
  fi 
fi

cd $APP_NAME && make 
make uninstall && make install

